package br.com.citta.dao.impl;

import br.com.citta.business.entities.FunPlanoreceita;
import br.com.citta.dao.FunPlanoreceitaDao;
import java.util.List;
import org.hibernate.Hibernate;
import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class FunPlanoreceitaDaoImpl extends HibernateDaoSupport implements FunPlanoreceitaDao {
    
    public List<FunPlanoreceita> find(String ano, String mes, String unidade, String recurso, String nivel){
        
        String sql = "from fun_planoreceita("+ano+","+mes+","+unidade+","+recurso+","+nivel+")";
        StringBuilder sb = new StringBuilder();
        sb.append("select chave, codigo, nome, recurso, orcado, atualizado, ");
        sb.append("arr_mes as arrMes, arr_parcial as arrParcial, nivel, ");
        sb.append("tipo_conta as tipoConta, ano_base as anoBase ");
        sb.append(sql);
        
        SQLQuery query = this.getSession().createSQLQuery(sb.toString());
        query.addScalar("chave", Hibernate.INTEGER);
        query.addScalar("codigo",Hibernate.STRING);
        query.addScalar("nome",Hibernate.STRING);
        query.addScalar("recurso",Hibernate.INTEGER);
        query.addScalar("orcado",Hibernate.DOUBLE);
        query.addScalar("atualizado",Hibernate.DOUBLE);
        query.addScalar("arrMes",Hibernate.DOUBLE);
        query.addScalar("arrParcial",Hibernate.DOUBLE);
        query.addScalar("nivel",Hibernate.INTEGER);
        query.addScalar("tipoConta",Hibernate.STRING);
        query.addScalar("anoBase",Hibernate.INTEGER);
        
        query.setResultTransformer(Transformers.aliasToBean(FunPlanoreceita.class));

        return query.list();
        
    }
    
}
